package com.distortiongames.level27.gameobjects
{
	import com.distortiongames.level27.components.MapComponent;
	import com.distortiongames.level27.components.MapSpatialComponent;
	import com.distortiongames.level27.components.render.TileRenderer;
	import com.distortiongames.level27.components.ValueComponent;
	import com.pblabs.core.PBGameObject;
	import flash.display.Stage;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class Tile extends PBGameObject
	{
		
		public var position:MapSpatialComponent;
		public var renderer:TileRenderer;
		public var value:ValueComponent;
		public var map:MapComponent;
		private var _visible:Boolean;
		private var _revealed:Boolean;
		public var north:Tile;
		public var south:Tile;
		public var east:Tile;
		public var west:Tile;
		
		[Inject]
		public var stage:Stage;
		
		override public function initialize():void
		{
			position = new MapSpatialComponent();
			renderer = new TileRenderer();
			value = new ValueComponent();
			map = new MapComponent();
			revealed = false;
			visible = false;
			
			renderer.addBinding("map", "@map.map");
			renderer.addBinding("position", "@position.point");
			renderer.addBinding("value", "@value.value");
			
			super.initialize();
		}
		
		public function onClick(e:*):void
		{
			trace(position.point);
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		public function get visible():Boolean
		{
			return _visible;
		}
		
		public function set visible(value:Boolean):void
		{
			_visible = value;
			renderer.visible = value;
		}
		
		public function get revealed():Boolean
		{
			return _revealed;
		}
		
		public function set revealed(value:Boolean):void
		{
			_revealed = value;
			renderer.revealed = value;
			if (north != null)
				north.visible = true;
			if (south != null)
				south.visible = true;
			if (east != null)
				east.visible = true;
			if (west != null)
				west.visible = true;
		}
	}
}

